<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\View;
Class Hot extends Index{
	public function __construct(Request $request)
	{
		parent::__construct($request);
	}
	//热门话题
	public function hottopic(){
		$page = Db::name('huati')->where(['huatitype'=>'1'])->order('addtime','desc')->paginate(6,false,['type' => 'bootstrap','var_page' => 'page']);
		// dump($page);
		$hottopic = $page->all();
		foreach ($hottopic as $key => $value) {
			$hottopic[$key]['nickname'] = Db::name('user')->value('nickname');
		}
		$this->assign('page',$page);
		$this->assign('hottopic',$hottopic);
		$this->assign('title','热门话题');
		return view('hottopic');
	}
	//热门话题详情
	public function hotdetail(){
		//热门话题
		$hotdetail = Db::name('huati')->where(['huatiid'=>input('huatiid')])->find();
		$hotdetail['nickname'] = Db::name('user')->where(['userid'=>$hotdetail['userid']])->value('nickname');
		//评论
		$chatcontent = Db::name('chat')->order('chattime asc')->where(['huatiid'=>$hotdetail['huatiid']])->select();
		foreach ($chatcontent as $key => $value) {
			$where['userid']=$chatcontent[$key]['userid'];
			$chatcontent[$key]['nickname'] = Db::name('user')->where($where)->value('nickname');
			$chatcontent[$key]['photo'] = Db::name('user')->where($where)->value('photo');
			if($chatcontent[$key]['huifuid']!=0){
				$chatcontent[$key]['huifunickname'] = Db::name('user')->where($where)->value('nickname');
			}else{
				$chatcontent[$key]['huifunickname']='';
			}
		}
		if(empty($chatcontent)){
			$chatcontent = '';
		}
		$this->assign('title',$hotdetail['huatititle']);
		$this->assign('chatcontent',$chatcontent);
		$this->assign('huati',$hotdetail);
		return view('hotdetail');
	}
}